package com.yunzheng.studyLeaveSystem.modules.admin.show.students.dao.Impl;

import com.yunzheng.studyLeaveSystem.modules.admin.show.students.dao.AdjustDao;
import com.yunzheng.studyLeaveSystem.utils.DBUtils;
import com.yunzheng.studyLeaveSystem.modules.admin.show.students.entity.adjuster;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class AdjustDaoImpl implements AdjustDao {
    @Override
    public List<adjuster> queryInformation(String name) throws Exception {
        Connection connection = DBUtils.getCon();
        List<adjuster> InformationList = new ArrayList<>();
        String sql = "select term,direction,leave_date,leave_class,adjust_date,adjust_class,reason from adjust where name =?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            adjuster adjuster = new adjuster();
            adjuster.setTerm(resultSet.getString("term"));
            adjuster.setDirection(resultSet.getString("direction"));
            adjuster.setLeave_date(resultSet.getString("leave_date"));
            adjuster.setLeave_class(resultSet.getString("leave_class"));
            adjuster.setAdjust_date(resultSet.getString("adjust_date"));
            adjuster.setAdjust_class(resultSet.getString("adjust_class"));
            adjuster.setReason(resultSet.getString("reason"));
            InformationList.add(adjuster);
        }
        DBUtils.release(resultSet, preparedStatement, connection);
        return InformationList;
    }
}